package ServerImp;

import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.rmi.RemoteException;
import java.util.logging.Level;
import java.util.logging.Logger;
import Shared.ClientInt;
import Shared.User;
import javax.swing.JOptionPane;
public class SignUp extends javax.swing.JFrame {
    //int fFlag=0,lFlag=0,uFlag=0,dFlag=0,mFlag=0,yFlag=0,eFlag=0,cFlag=0,pFlag=0,cpFlag=0;
    int[] flag = new int[10];
    boolean fFlag=false;
    private serverImp server;
    public SignUp(serverImp server) {
        this.server=server;
        initComponents();
        this.setLocation(500,150);
        firsterror .setVisible(false);
        lasterror.setVisible(false);
        usererror.setVisible(false);
        emailerror.setVisible(false);
        countryerror.setVisible(false);
        passerror.setVisible(false);
        passconfirmerror.setVisible(false);
        dayerror.setVisible(false);
        montherror.setVisible(false);
        yearerror.setVisible(false);
        signerror.setVisible(false);
        emailerror2.setVisible(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelSignUp = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        userName = new javax.swing.JLabel();
        email = new javax.swing.JLabel();
        password = new javax.swing.JLabel();
        confirmPass = new javax.swing.JLabel();
        country = new javax.swing.JLabel();
        nameText = new javax.swing.JTextField();
        emailText = new javax.swing.JTextField();
        passText = new javax.swing.JPasswordField();
        confirmText = new javax.swing.JPasswordField();
        countryList = new javax.swing.JComboBox();
        signupButton = new javax.swing.JButton();
        firstName = new javax.swing.JLabel();
        firstnameText = new javax.swing.JTextField();
        lastName = new javax.swing.JLabel();
        lastnameText = new javax.swing.JTextField();
        day = new javax.swing.JComboBox();
        month = new javax.swing.JComboBox();
        year = new javax.swing.JComboBox();
        d = new javax.swing.JLabel();
        m = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        passerror = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        passconfirmerror = new javax.swing.JLabel();
        emailerror = new javax.swing.JLabel();
        usererror = new javax.swing.JLabel();
        firsterror = new javax.swing.JLabel();
        lasterror = new javax.swing.JLabel();
        countryerror = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        dayerror = new javax.swing.JLabel();
        montherror = new javax.swing.JLabel();
        yearerror = new javax.swing.JLabel();
        signerror = new javax.swing.JLabel();
        emailerror2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("ChatUp(Add New User)");
        setModalExclusionType(null);
        setResizable(false);

        panelSignUp.setBackground(new java.awt.Color(255, 255, 255));
        panelSignUp.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 18)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(1, 42, 139));
        jLabel1.setText("User Registeration ");

        userName.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        userName.setForeground(new java.awt.Color(41, 49, 76));
        userName.setText("User Name");

        email.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        email.setForeground(new java.awt.Color(41, 49, 76));
        email.setText("Email");

        password.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        password.setForeground(new java.awt.Color(41, 49, 76));
        password.setText("Password");

        confirmPass.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        confirmPass.setForeground(new java.awt.Color(41, 49, 76));
        confirmPass.setText("Confirm Password");

        country.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        country.setForeground(new java.awt.Color(41, 49, 76));
        country.setText("Country");

        nameText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                nameTextFocusLost(evt);
            }
        });
        nameText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                nameTextKeyTyped(evt);
            }
        });

        emailText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                emailTextFocusLost(evt);
            }
        });
        emailText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                emailTextKeyTyped(evt);
            }
        });

        passText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                passTextFocusLost(evt);
            }
        });
        passText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                passTextKeyTyped(evt);
            }
        });

        confirmText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                confirmTextFocusLost(evt);
            }
        });
        confirmText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                confirmTextKeyTyped(evt);
            }
        });

        countryList.setBackground(new java.awt.Color(255, 255, 255));
        countryList.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--Select--", "Afghanistan", "Albania", "Algeria", "Angola", "Arabia, Saudi", "Argentina", "Australia", "Austria", "Bahrain", "Belgium", "Botswana", "Bouvet Island", "Brazil", "Cambodia", "Cameroon", "Canada", "Central African Republic", "Chile", "China", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", "Eritrea", "Estonia", "Ethiopia" }));
        countryList.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                countryListFocusLost(evt);
            }
        });

        signupButton.setBackground(new java.awt.Color(102, 0, 51));
        signupButton.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 18)); // NOI18N
        signupButton.setForeground(new java.awt.Color(255, 255, 255));
        signupButton.setText("SignUp");
        signupButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                signupButtonActionPerformed(evt);
            }
        });

        firstName.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        firstName.setForeground(new java.awt.Color(41, 49, 76));
        firstName.setText("First Name");

        firstnameText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                firstnameTextFocusLost(evt);
            }
        });
        firstnameText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                firstnameTextKeyTyped(evt);
            }
        });

        lastName.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        lastName.setForeground(new java.awt.Color(41, 49, 76));
        lastName.setText("Last Name");

        lastnameText.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                lastnameTextFocusLost(evt);
            }
        });
        lastnameText.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                lastnameTextKeyTyped(evt);
            }
        });

        day.setBackground(new java.awt.Color(255, 255, 255));
        day.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        day.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dayActionPerformed(evt);
            }
        });
        day.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                dayFocusLost(evt);
            }
        });

        month.setBackground(new java.awt.Color(255, 255, 255));
        month.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" }));
        month.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monthActionPerformed(evt);
            }
        });
        month.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                monthFocusLost(evt);
            }
        });

        year.setBackground(new java.awt.Color(255, 255, 255));
        year.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "----", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015" }));
        year.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                yearActionPerformed(evt);
            }
        });
        year.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                yearFocusLost(evt);
            }
        });

        d.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        d.setForeground(new java.awt.Color(41, 49, 76));
        d.setText("Day");

        m.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        m.setForeground(new java.awt.Color(41, 49, 76));
        m.setText("Month");

        jLabel2.setFont(new java.awt.Font("DejaVu Serif Condensed", 1, 14)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(41, 49, 76));
        jLabel2.setText("Year");

        passerror.setForeground(new java.awt.Color(240, 27, 27));
        passerror.setText("Password Not valid");

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ServerImp/signup.png"))); // NOI18N

        passconfirmerror.setForeground(new java.awt.Color(240, 27, 27));
        passconfirmerror.setText("Password Does not match");

        emailerror.setForeground(new java.awt.Color(240, 27, 27));
        emailerror.setText("Email not valid");

        usererror.setForeground(new java.awt.Color(240, 27, 27));
        usererror.setText("User Name is empty");

        firsterror.setForeground(new java.awt.Color(240, 27, 27));
        firsterror.setText("First Name is empty");

        lasterror.setForeground(new java.awt.Color(240, 27, 27));
        lasterror.setText("Last Name is empty");

        countryerror.setForeground(new java.awt.Color(240, 27, 27));
        countryerror.setText("Select a country");

        dayerror.setForeground(new java.awt.Color(240, 27, 27));
        dayerror.setText("*Missing");

        montherror.setForeground(new java.awt.Color(240, 27, 27));
        montherror.setText("*Missing");

        yearerror.setForeground(new java.awt.Color(240, 27, 27));
        yearerror.setText("*Missing");

        signerror.setForeground(new java.awt.Color(240, 27, 27));
        signerror.setText("*Missing Field(s) ");

        emailerror2.setForeground(new java.awt.Color(240, 27, 27));
        emailerror2.setText("*Exist Email");

        javax.swing.GroupLayout panelSignUpLayout = new javax.swing.GroupLayout(panelSignUp);
        panelSignUp.setLayout(panelSignUpLayout);
        panelSignUpLayout.setHorizontalGroup(
            panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelSignUpLayout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelSignUpLayout.createSequentialGroup()
                        .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelSignUpLayout.createSequentialGroup()
                                .addGap(31, 31, 31)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 330, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(panelSignUpLayout.createSequentialGroup()
                                        .addGap(49, 49, 49)
                                        .addComponent(jLabel3))
                                    .addGroup(panelSignUpLayout.createSequentialGroup()
                                        .addGap(18, 18, 18)
                                        .addComponent(jLabel4))))
                            .addGroup(panelSignUpLayout.createSequentialGroup()
                                .addComponent(passerror)
                                .addGap(130, 130, 130)
                                .addComponent(passconfirmerror)))
                        .addContainerGap())
                    .addGroup(panelSignUpLayout.createSequentialGroup()
                        .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(firstName)
                            .addComponent(email)
                            .addComponent(userName)
                            .addComponent(nameText, javax.swing.GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
                            .addComponent(emailText)
                            .addComponent(firstnameText)
                            .addComponent(password)
                            .addComponent(firsterror)
                            .addComponent(usererror)
                            .addGroup(panelSignUpLayout.createSequentialGroup()
                                .addComponent(emailerror)
                                .addGap(32, 32, 32)
                                .addComponent(emailerror2))
                            .addComponent(passText))
                        .addGap(18, 18, 18)
                        .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelSignUpLayout.createSequentialGroup()
                                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(panelSignUpLayout.createSequentialGroup()
                                        .addGap(0, 0, Short.MAX_VALUE)
                                        .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(lastName)
                                            .addComponent(lastnameText, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(lasterror)))
                                    .addComponent(confirmText))
                                .addGap(119, 119, 119))
                            .addGroup(panelSignUpLayout.createSequentialGroup()
                                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(countryList, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(panelSignUpLayout.createSequentialGroup()
                                        .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(panelSignUpLayout.createSequentialGroup()
                                                .addComponent(d)
                                                .addGap(45, 45, 45)
                                                .addComponent(m))
                                            .addGroup(panelSignUpLayout.createSequentialGroup()
                                                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(day, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(dayerror))
                                                .addGap(18, 18, 18)
                                                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(montherror)
                                                    .addComponent(month, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                        .addGap(18, 18, 18)
                                        .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel2)
                                            .addComponent(yearerror)))
                                    .addComponent(confirmPass)
                                    .addComponent(country)
                                    .addComponent(countryerror))
                                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))))
            .addGroup(panelSignUpLayout.createSequentialGroup()
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelSignUpLayout.createSequentialGroup()
                        .addGap(222, 222, 222)
                        .addComponent(signerror))
                    .addGroup(panelSignUpLayout.createSequentialGroup()
                        .addGap(164, 164, 164)
                        .addComponent(signupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 0, Short.MAX_VALUE))
        );
        panelSignUpLayout.setVerticalGroup(
            panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelSignUpLayout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addGap(30, 30, 30)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(firstName, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lastName))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(firstnameText, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lastnameText, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(firsterror)
                    .addComponent(lasterror))
                .addGap(11, 11, 11)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(d)
                    .addComponent(m)
                    .addComponent(jLabel2)
                    .addComponent(userName, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(nameText, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(day, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(month, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(year, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(usererror)
                    .addComponent(dayerror)
                    .addComponent(montherror)
                    .addComponent(yearerror))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelSignUpLayout.createSequentialGroup()
                        .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(emailText, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelSignUpLayout.createSequentialGroup()
                        .addComponent(country, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(countryList, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(emailerror)
                    .addComponent(countryerror)
                    .addComponent(emailerror2))
                .addGap(18, 18, 18)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(confirmPass))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passText, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(confirmText, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelSignUpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(passerror)
                    .addComponent(passconfirmerror))
                .addGap(18, 18, 18)
                .addComponent(signupButton, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(signerror))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelSignUp, javax.swing.GroupLayout.PREFERRED_SIZE, 541, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(panelSignUp, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        getAccessibleContext().setAccessibleParent(this);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void signupButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_signupButtonActionPerformed
  
        fFlag = true;
        for(int check:flag)
        {
           if(check == 0)
           {
               fFlag=false;
               //System.out.println(fFlag);
           }
        }
        if(fFlag)
        {
            signerror.setVisible(false);
            System.out.println(fFlag); 
            User user=new User();
            user.setUserFName(firstnameText.getText());
            user.setUserLname(lastnameText.getText());
            user.setUserDate(year.getSelectedItem()+"-"+month.getSelectedItem()+"-"+day.getSelectedIndex());
            user.setUserCountry((String) countryList.getSelectedItem());
            user.setUserMail(emailText.getText());
            user.setUserPass(new String(passText.getPassword()));
            user.setUserName(nameText.getText());
            System.out.println(nameText.getText());
            int val=0;
            try {
                val = server.registerUser(user);
            } catch (RemoteException ex) {
                Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, null, ex);
            }
            if(val==0)
            {
                this.setVisible(false);
                final JOptionPane pane = new JOptionPane();
                pane.showMessageDialog(SignUp.this, "User already registered", null, JOptionPane.OK_OPTION);
                pane.setLocation(250, 250);
            }else{
                this.setVisible(false);
            }
            
        }
        else
        {
            signerror.setVisible(true);
        }   
        if(signerror.isVisible())
        {
            if(lastnameText.getText().equals(""))
            {
                lasterror.setVisible(true);
            }
            if(firstnameText.getText().equals(""))
            {
                firsterror.setVisible(true);
            }
            if(nameText.getText().equals(""))
            {
                usererror.setVisible(true);
            }
        }
    }//GEN-LAST:event_signupButtonActionPerformed

    private void firstnameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_firstnameTextFocusLost
       if(!firstnameText.getText().equals(""))//firstname
       {
            firsterror.setVisible(false);
            flag[0] = 1;
       }else
        {
            firsterror.setVisible(true);
            flag[0] = 0;
        }    
        
    }//GEN-LAST:event_firstnameTextFocusLost

    private void lastnameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_lastnameTextFocusLost
       if(!lastnameText.getText().equals(""))//lastname
       {
           lasterror.setVisible(false);    
           flag[1] = 1;
       }else
        {
            lasterror.setVisible(true);
            flag[1] = 0;
        }
    }//GEN-LAST:event_lastnameTextFocusLost

    private void nameTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_nameTextFocusLost
       if(!nameText.getText().equals(""))//username
       {
           usererror.setVisible(false);           
           flag[2] = 1;
       }else
        {
            usererror.setVisible(true);
            flag[2] = 0;
        }
    }//GEN-LAST:event_nameTextFocusLost

    private void emailTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_emailTextFocusLost
        if(!emailText.getText().equals(""))//email
            {
                String mail=emailText.getText();
                String myPattern = "([\\w\\-\\.]+)@((\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|(([\\w\\-]+\\.)+)([a-zA-Z]{2,4}))";
                Pattern p=Pattern.compile(myPattern);
                Matcher m=p.matcher(mail);
                boolean matchFound=m.find();
                if(!(matchFound))
                {
                    emailerror.setVisible(true);
                    flag[3] = 0;
                }
                else
                {
                    int checked = 0;
                    try {
                        checked = server.checkMail(emailText.getText());
                    } catch (RemoteException ex) {
                        Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    System.out.println(checked);
                    if(checked == 1)
                    {
                        emailerror.setVisible(false);
                        emailerror2.setVisible(false);
                        flag[3] = 1;
                    }
                    else
                    {
                        emailerror2.setVisible(true);
                        flag[3] = 0;
                    }
                }
            }
        else
            {
                emailerror.setVisible(true);
                flag[3] = 0;
            }
    }//GEN-LAST:event_emailTextFocusLost

    private void countryListFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_countryListFocusLost
        // TODO add your handling code here:
        int index = countryList.getSelectedIndex();
        if(index == 0)
        {
            countryerror.setVisible(true);
            flag[4] = 0;
        }
        else
        {
            countryerror.setVisible(false);
            flag[4] = 1;
        }
    }//GEN-LAST:event_countryListFocusLost

    private void passTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_passTextFocusLost
       if(!new String(passText.getPassword()).equals(""))
       {
            boolean goodLength = false;    
            // check if the String is over 10 characters long.  
            // If it isn't too long, set goodLength to true  
            if(new String(passText.getPassword()).length() >= 10)
            {   
                 goodLength = true;  
                 passerror.setVisible(false);
                 flag[5] = 1;
            }
            else if(new String(passText.getPassword()).length() <10)
            {
                passerror.setVisible(true);
                flag[5] = 0;
            }
       }
       else
       {
           passerror.setVisible(true);
           flag[5] = 0;
       }    
    }//GEN-LAST:event_passTextFocusLost

    private void confirmTextFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_confirmTextFocusLost
        if(!new String(confirmText.getPassword()).equals(""))
            {
                char[] pass=passText.getPassword();
                char[] confirmpass=confirmText.getPassword();
                String newpass=new String(pass);
                String newconfirmpass= new String(confirmpass);
                if(!newpass.equals(newconfirmpass))
                {
                    passconfirmerror.setVisible(true);
                    flag[6] = 0;
                }
                else
                {
                    passconfirmerror.setVisible(false);
                    flag[6] = 1;
                }
           }
        else
            {
                passconfirmerror.setVisible(true);
                flag[6] = 0;
            }
    }//GEN-LAST:event_confirmTextFocusLost

    private void dayFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dayFocusLost
        // TODO add your handling code here:
        int index = day.getSelectedIndex();
        if(index == 0)
        {
            dayerror.setVisible(true);
            flag[7] = 0;
        }
        else
        {
            dayerror.setVisible(false);
            flag[7] = 1;
        }
    }//GEN-LAST:event_dayFocusLost

    private void monthFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_monthFocusLost
        // TODO add your handling code here:
        int index = month.getSelectedIndex();
        if(index == 0)
        {
            montherror.setVisible(true);
            flag[8] = 0;
        }
        else
        {
            montherror.setVisible(false);
            flag[8] = 1;
        }
    }//GEN-LAST:event_monthFocusLost

    private void yearFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_yearFocusLost
        // TODO add your handling code here:
        int index = year.getSelectedIndex();
        if(index == 0)
        {
            yearerror.setVisible(true);
            flag[9] = 0;
        }
        else
        {
            yearerror.setVisible(false);
            flag[9] = 1;
        }
    }//GEN-LAST:event_yearFocusLost

    private void dayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dayActionPerformed
        // TODO add your handling code here:
        int index = day.getSelectedIndex();
        if(index == 0)
        {
            dayerror.setVisible(true);
            flag[7] = 0;
        }
        else
        {
            dayerror.setVisible(false);
            flag[7] = 1;
        }
    }//GEN-LAST:event_dayActionPerformed

    private void monthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthActionPerformed
        // TODO add your handling code here:
        int index = month.getSelectedIndex();
        if(index == 0)
        {
            montherror.setVisible(true);
            flag[8] = 0;
        }
        else
        {
            montherror.setVisible(false);
            flag[8] = 1;
        }
    }//GEN-LAST:event_monthActionPerformed

    private void yearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_yearActionPerformed
        // TODO add your handling code here:
        int index = year.getSelectedIndex();
        if(index == 0)
        {
            yearerror.setVisible(true);
            flag[9] = 0;
        }
        else
        {
            yearerror.setVisible(false);
            flag[9] = 1;
        }
    }//GEN-LAST:event_yearActionPerformed

    private void firstnameTextKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_firstnameTextKeyTyped
        // TODO add your handling code here:
        if(!firstnameText.getText().equals(""))//firstname
       {
            firsterror.setVisible(false);
            flag[0] = 1;
       }else
        {
            firsterror.setVisible(true);
            flag[0] = 0;
        } 
    }//GEN-LAST:event_firstnameTextKeyTyped

    private void lastnameTextKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lastnameTextKeyTyped
        // TODO add your handling code here:
        if(!lastnameText.getText().equals(""))//lastname
       {
           lasterror.setVisible(false);    
           flag[1] = 1;
       }else
        {
            lasterror.setVisible(true);
            flag[1] = 0;
        }
    }//GEN-LAST:event_lastnameTextKeyTyped

    private void nameTextKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_nameTextKeyTyped
        // TODO add your handling code here:
        if(!nameText.getText().equals(""))//username
       {
           usererror.setVisible(false);           
           flag[2] = 1;
       }else
        {
            usererror.setVisible(true);
            flag[2] = 0;
        }
    }//GEN-LAST:event_nameTextKeyTyped

    private void passTextKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_passTextKeyTyped
        // TODO add your handling code here:
        if(!new String(passText.getPassword()).equals(""))
       {
            boolean goodLength = false;    
            // check if the String is over 10 characters long.  
            // If it isn't too long, set goodLength to true  
            if(new String(passText.getPassword()).length() >= 10)
            {   
                 goodLength = true;  
                 passerror.setVisible(false);
                 flag[5] = 1;
            }
            else if(new String(passText.getPassword()).length() <10)
            {
                passerror.setVisible(true);
                flag[5] = 0;
            }
       }
       else
       {
           passerror.setVisible(true);
           flag[5] = 0;
       }
    }//GEN-LAST:event_passTextKeyTyped

    private void confirmTextKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_confirmTextKeyTyped
        // TODO add your handling code here:
        if(!new String(confirmText.getPassword()).equals(""))
            {
                char[] pass=passText.getPassword();
                char[] confirmpass=confirmText.getPassword();
                String newpass=new String(pass);
                String newconfirmpass= new String(confirmpass);
                if(!newpass.equals(newconfirmpass))
                {
                    passconfirmerror.setVisible(true);
                    flag[6] = 0;
                }
                else
                {
                    passconfirmerror.setVisible(false);
                    flag[6] = 1;
                }
           }
        else
            {
                passconfirmerror.setVisible(true);
                flag[6] = 0;
            }
    }//GEN-LAST:event_confirmTextKeyTyped

    private void emailTextKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_emailTextKeyTyped
        // TODO add your handling code here:
        if(!emailText.getText().equals(""))//email
            {
                String mail=emailText.getText();
                String myPattern = "([\\w\\-\\.]+)@((\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\])|(([\\w\\-]+\\.)+)([a-zA-Z]{2,4}))";
                Pattern p=Pattern.compile(myPattern);
                Matcher m=p.matcher(mail);
                boolean matchFound=m.find();
                if(!(matchFound))
                {
                    emailerror.setVisible(true);
                    flag[3] = 0;
                }
                else
                {
                    int checked = 0;
                    try {
                        checked = server.checkMail(emailText.getText());
                    } catch (RemoteException ex) {
                        Logger.getLogger(SignUp.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    System.out.println(checked);
                    if(checked == 1)
                    {
                        emailerror.setVisible(false);
                        emailerror2.setVisible(false);
                        flag[3] = 1;
                    }
                    else
                    {
                        emailerror2.setVisible(true);
                        flag[3] = 0;
                    }
                }
            }
        else
            {
                emailerror.setVisible(true);
                flag[3] = 0;
            }
    }//GEN-LAST:event_emailTextKeyTyped
   
 

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel confirmPass;
    private javax.swing.JPasswordField confirmText;
    private javax.swing.JLabel country;
    private javax.swing.JComboBox countryList;
    private javax.swing.JLabel countryerror;
    private javax.swing.JLabel d;
    private javax.swing.JComboBox day;
    private javax.swing.JLabel dayerror;
    private javax.swing.JLabel email;
    private javax.swing.JTextField emailText;
    private javax.swing.JLabel emailerror;
    private javax.swing.JLabel emailerror2;
    private javax.swing.JLabel firstName;
    private javax.swing.JLabel firsterror;
    private javax.swing.JTextField firstnameText;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel lastName;
    private javax.swing.JLabel lasterror;
    private javax.swing.JTextField lastnameText;
    private javax.swing.JLabel m;
    private javax.swing.JComboBox month;
    private javax.swing.JLabel montherror;
    private javax.swing.JTextField nameText;
    private javax.swing.JPanel panelSignUp;
    private javax.swing.JPasswordField passText;
    private javax.swing.JLabel passconfirmerror;
    private javax.swing.JLabel passerror;
    private javax.swing.JLabel password;
    private javax.swing.JLabel signerror;
    private javax.swing.JButton signupButton;
    private javax.swing.JLabel userName;
    private javax.swing.JLabel usererror;
    private javax.swing.JComboBox year;
    private javax.swing.JLabel yearerror;
    // End of variables declaration//GEN-END:variables
}
